package com.china08.yxyapi.repository.mg;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import com.china08.yxyapi.entity.mg.office.YxyNoticeOutter;

public interface YxyNoticeOutterRepository extends MongoRepository<YxyNoticeOutter, String> {

    Page<YxyNoticeOutter> findByUserIdAndEdbIdAndDeleteStatus(String userId, String edbId, int deleteStatus, Pageable pageable);

    @Query(value = "{'receive_school':{'$elemMatch':{'schoolId':?0,'isDelete':?1}}}")
    List<YxyNoticeOutter> findByReceiveSchoolSchoolIdAndReceiveSchoolIsDelete(String edbId, int isDelete, Pageable pageable);

    @Query(value = "{'receive_school':{'$elemMatch':{'schoolId':?0,'isDelete':?1}}}")
    List<YxyNoticeOutter> findByReceiveSchoolSchoolIdAndReceiveSchoolIsDelete(String edbId, int isDelete);

    @Query(value = "{'receive_school':{'$elemMatch':{'schoolId':?0,'isDelete':?1}}}", count = true)
    Integer countByReceiveSchoolSchoolIdAndReceiveSchoolIsDelete(String edbId, int isDelete);

    @Query(value = "{'id':{$in:?0},'receive_school':{'$elemMatch':{'schoolId':?1,'isDelete':?2}}}")
    List<YxyNoticeOutter> findByIdInAndReceiveSchoolSchoolIdAndReceiveSchoolIsDelete(List<String> idLst, String edbId, int isDelete);

    List<YxyNoticeOutter> findByIdInAndEdbIdAndDeleteStatus(List<String> idLst, String edbId, int deleteStatus);

    YxyNoticeOutter findById(String id);

    @Query(value = "{'id':?0,'receive_school':{'$elemMatch':{'schoolId':?1,'isRead':?2}}}")
    List<YxyNoticeOutter> findByIdAndReceiveSchoolSchoolIdAndReceiveSchoolIsRead(String id, String schoolId, int isRead);

    @Query(value = "{'receive_school':{'$elemMatch': {'schoolId':?0,'isRead':?1,'isDelete':?2}}}", count = true)
    Integer countByReceiveSchoolSchoolIdAndReceiveSchoolIsReadAndReceiveSchoolIsDelete(String schoolId, int isRead, int isDelete);

    @Query(value = "{'receive_school':{'$elemMatch':{'schoolId':?0,'isDelete':?1,'isRead':?2}}}")
    List<YxyNoticeOutter> findByReceiveSchoolSchoolIdAndReceiveSchoolIsDeleteAndReceiveSchoolIsRead(String edbId, int isDelete, int receiveSchoolIsRead, Pageable pageable);

    @Query(value = "{'receive_school':{'$elemMatch':{'schoolId':?0,'isDelete':?1,'isRead':?2}}}", count = true)
    Integer countByEdbIdAndReceiveSchoolIsDelete(String edbId, int isDelete, int receiveSchoolIsRead);

    @Query(value = "{'receive_school':{'$elemMatch':{'schoolId':?0,'isDelete':?1,'isRead':?2}}}", count = true)
    Integer countByReceiveSchoolSchoolIdAndReceiveSchoolIsDeleteAndReceiveSchoolIsRead(String edbId, int isDelete, int receiveSchoolIsRead);

}
